/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.service;

import cz.muni.restinterface.CourierDTO;
import cz.muni.restinterface.CustomerDTO;
import cz.muni.dto.TarrifDTO;
import cz.muni.entities.Courier;
import cz.muni.entities.Customer;
import cz.muni.entities.Tarrif;

/**
 *
 * @author sparrow
 */
public class DtoConversionHelper {

    /**
     *
     * @param customer
     * @return
     */
    public CustomerDTO mapToDTO(Customer customer) {
        if (customer == null) {
            return null;
        }
        CustomerDTO customerDTO = new CustomerDTO();

        customerDTO.setCity(customer.getCity());
        customerDTO.setEmail(customer.getEmail());
        customerDTO.setFirstName(customer.getFirstName());
        customerDTO.setId(customer.getId());
        customerDTO.setLastName(customer.getLastName());
        customerDTO.setPhoneNumber(customer.getPhoneNumber());
        customerDTO.setPostalCode(customer.getPostalCode());
        customerDTO.setStreet(customer.getStreet());
        customerDTO.setStreetNumber(customer.getStreetNumber());

        return customerDTO;
    }

    public Customer mapFromDTO(CustomerDTO customerDTO) {
        if (customerDTO == null) {
            return null;
        }
        Customer customer = new Customer();

        customer.setCity(customerDTO.getCity());
        customer.setEmail(customerDTO.getEmail());
        customer.setFirstName(customerDTO.getFirstName());
        customer.setId(customerDTO.getId());
        customer.setLastName(customerDTO.getLastName());
        customer.setPostalCode(customerDTO.getPostalCode());
        customer.setPhoneNumber(customerDTO.getPhoneNumber());
        customer.setStreet(customerDTO.getStreet());
        customer.setStreetNumber(customerDTO.getStreetNumber());

        return customer;
    }

    public CourierDTO mapToDTO(Courier courier) {
        if (courier == null) {
            return null;
        }
        CourierDTO courierDTO = new CourierDTO();
        courierDTO.setId(courier.getId());
        courierDTO.setFirstName(courier.getFirstName());
        courierDTO.setLastName(courier.getLastName());
        courierDTO.setUserName(courier.getUserName());
        return courierDTO;
    }
    
    public TarrifDTO mapToDTO(Tarrif tarrif) {
    
         if (tarrif == null) {
              return null;
         }
         TarrifDTO tarrifDTO = new TarrifDTO();
         tarrifDTO.setId(tarrif.getId());
         tarrifDTO.setDeliveryFee(tarrif.getDeliveryFee());
         tarrifDTO.setName(tarrif.getName());
         tarrifDTO.setPricePerKG(tarrif.getPricePerKG());
         tarrifDTO.setPricePerKM(tarrif.getPricePerKM());
         
         return tarrifDTO;
    }

    /**
     *
     * @param courierDTO
     * @return
     */
    public Courier mapFromDTO(CourierDTO courierDTO) {
        if (courierDTO == null) {
            return null;
        }
        Courier courier = new Courier();
        courier.setFirstName(courierDTO.getFirstName());
        courier.setId(courierDTO.getId());
        courier.setLastName(courierDTO.getLastName());
        courier.setUserName(courierDTO.getUserName());

        return courier;
    }
    
    public Tarrif mapFromDTO(TarrifDTO tarrifDTO) {
    
        if (tarrifDTO == null) {
            return null;
        }
        
        Tarrif tarrif = new Tarrif();
        tarrif.setDeliveryFee(tarrifDTO.getDeliveryFee());
        tarrif.setId(tarrifDTO.getId());
        tarrif.setName(tarrifDTO.getName());
        tarrif.setPricePerKG(tarrifDTO.getPricePerKG());
        tarrif.setPricePerKM(tarrifDTO.getPricePerKM());
        
        return tarrif;
        
    }
}
